package com.hu.config.rabbitMQ;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class Sender {
    @Autowired
    private AmqpTemplate rabbitTemplate;
    /**
     * 精确匹配
     */
    public void send(int i) {
        //发送者和接收者的queue name必须一致，不然不能接收
        String context =i+ "hello " + new Date();
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("hello", context);
    }

    /**
     * topic 通配符匹配
     */
    public void send1(int i) {
        String context = i+"hi";
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("exchange", "hi", context);
    }

    public void send2(int i) {
        String context = i+"hello";
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("exchange", "hello", context);
    }

    /**
     * fanout 直接匹配所有
     */
    public void send3(int i) {
        String context = i+"hi ";
        System.out.println("Sender : " + context);
        this.rabbitTemplate.convertAndSend("fexchange","", context);
    }


}
